home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / dfutil2.zip / ADDNUM.ZIP / ADDNUM.BAS next >
BASIC Source File  |  1990-11-10  |  4KB  |  142 lines

  1. 'ADDNUMBER ADD OR REMOVES LINENUMBERS TO FILES                                     *
  2. 'Designed as an assistance to debugging unnumbered QuickBasic code
  3. '(c) 1990 by DAVID WESSON, PhD.
  4. '
  5. ' $INCLUDE: 'qb.bi'
  6. '
  7. DECLARE FUNCTION exists (filename$)
  8.  
  9. DIM SHARED inregs AS RegTypeX, outregs AS RegTypeX
  10. CONST YES = 1, NO = 0
  11.  
  12.     CLS
  13. READCOMMAND:
  14.     a$ = COMMAND$
  15. SPLITLINE:                                             'separate words in line
  16.       DIM arg$(4)
  17.       W = 1: word$ = ""                                 'and returns lowercase
  18.       FOR x = 1 TO LEN(a$)
  19.             y$ = MID$(a$, x, 1): y = ASC(y$)
  20.                     IF y = 32 AND LEN(word$) < 1 THEN GOTO NEXTX
  21.                     IF y > 64 AND y < 91 THEN
  22.                           y$ = CHR$(y + 32)
  23.                           word$ = word$ + y$
  24.                           GOTO NEXTX
  25.                     END IF
  26.                     IF y = 32 AND LEN(word$) > 1 THEN
  27.                           arg$(W) = word$: W = W + 1: word$ = ""
  28.                           GOTO NEXTX
  29.             END IF
  30.          word$ = word$ + y$
  31. NEXTX: NEXT x
  32.       IF LEN(word$) > 1 THEN arg$(W) = word$
  33. BEGINNING:
  34.     infile$ = arg$(1)
  35.     IF infile$ = "" THEN GOTO HELP
  36.     IF exists(infile$) = NO THEN GOTO NOFIND
  37.     OPEN infile$ FOR INPUT AS 1
  38.     GOSUB filename
  39.     answer$ = file$
  40.     oldfile$ = file$ + ".OLD"
  41.     outfile$ = file$ + ".tmp"
  42.     OPEN outfile$ FOR OUTPUT AS #2
  43.     IF arg$(2) = "/a" THEN
  44.         pro$ = "Adding linenumbers for "
  45.     ELSEIF arg$(2) = "/r" THEN
  46.         pro$ = "Removing linenumbers for "
  47.     ELSE GOTO BADINSTRUCT
  48.     END IF
  49. HEADER:
  50.       COLOR 15: PRINT "ADD NUMBER  "; : COLOR 7: PRINT "adds or removes linenumbers from files."
  51.       PRINT pro$; infile$; ", creating backup as "; oldfile$
  52.       PRINT "Hit [Ctrl]+[Break] to terminate."
  53.       GOSUB TIME
  54.       PRINT "      Start time:"; newtime$
  55.       PRINT " Processing Line: "
  56.       z = 0
  57. CYCLE:
  58.     WHILE NOT EOF(1)
  59.         LINE INPUT #1, l$
  60.         LOCATE 5, 18: PRINT z
  61.         z = z + 1
  62.         IF arg$(2) = "/a" THEN
  63.             PRINT #2, USING "####"; z;
  64.             PRINT #2, " "; l$
  65.         ELSEIF arg$(2) = "/r" THEN
  66.             PRINT #2, MID$(l$, 6)
  67.         END IF
  68.     WEND
  69.     GOTO FINISH
  70. '*************************** GENERAL SUBROUTINES ******************************
  71. TIME:
  72.       intime$ = TIME$                                     'current time changed
  73.             hour$ = MID$(intime$, 1, 2)                     'to newtime$
  74.             min$ = MID$(intime$, 4, 2)
  75.             sec$ = MID$(intime$, 7, 2)
  76.             hour = VAL(hour$)
  77.                   IF hour < 12 THEN ampm$ = "am" ELSE ampm$ = "pm"
  78.                   IF hour > 12 THEN hour = hour - 12
  79.             hour$ = STR$(hour)
  80.       newtime$ = hour$ + ":" + min$ + ":" + sec$ + " " + ampm$
  81.       RETURN
  82. '****************************** HELP AND ERROR ROUTINES ***********************
  83. HELP:
  84.       PRINT " "
  85.       PRINT "ADDNUMBER  adds or removes linenumbers from files. "
  86.       PRINT "                                            (c) 1990 David A. Wesson"
  87.       PRINT " "
  88.       PRINT "Syntax: ADDNUM [d:]oldfile  /A/R"
  89.       PRINT " where  oldfile = original file (with .ext) [drive optional]      "
  90.       PRINT "       /A or /R = /A to ADD linenumbers, /R to REMOVE linenumbers"
  91.       PRINT ""
  92.       PRINT "NOTE: This procedure will work on any ASCII file, but only"
  93.       PRINT "      9999 lines will be numbered. Use REMOVE only on files"
  94.       PRINT "      with numbers ADDED by ADDNUMBER, since the first 5"
  95.       PRINT "      characters of each line are dropped in REMOVE processing."
  96.       PRINT "      A backup of the original called .OLD will be made."
  97.       END
  98. NOFIND:
  99.       PRINT "ERROR: No file by that name found."
  100.       GOTO HELP
  101. BADFILE:
  102.       PRINT "ERROR: Duplicate or missing filename."
  103.       GOTO HELP
  104. BADINSTRUCT:
  105.       PRINT "ERROR: Bad or missing instruction."
  106.       GOTO HELP
  107. FINISH:
  108.       CLOSE
  109.       IF exists(oldfile$) = YES THEN KILL oldfile$
  110.       NAME infile$ AS oldfile$
  111.       NAME outfile$ AS infile$
  112.       GOSUB TIME
  113.       PRINT "     Finish time:"; newtime$
  114.       END
  115. filename:                                         'splits infile$ into
  116.           period = INSTR(infile$, ".")              'file$ and ext$
  117.         IF period = 0 THEN
  118.             file$ = UCASE$(infile$)
  119.             ext$ = ""
  120.             ELSE
  121.                 file$ = UCASE$(LEFT$(infile$, period - 1))
  122.                 ext$ = UCASE$(MID$(infile$, period + 1))
  123.         END IF
  124.         RETURN
  125.  
  126. FUNCTION exists (search$)
  127.      savefile$ = search$
  128.      inregs.ax = &H4E00
  129.      inregs.cx = 1     '3 for hidden
  130.      search$ = search$ + CHR$(0)
  131.      inregs.dx = SADD(search$)
  132.      inregs.ds = -1
  133.      CALL INTERRUPTX(&H21, inregs, outregs)
  134.      IF (outregs.flags AND 1) = 1 THEN
  135.             exists = NO
  136.      ELSE
  137.             exists = YES
  138.      END IF
  139.      search$ = savefile$
  140. END FUNCTION
  141.  
  142.